package tech.cn.note.word.fun;

import java.util.Optional;

import com.deepoove.poi.render.compute.RenderDataCompute;

import org.springframework.stereotype.Service;

@Service
public class Nvl implements RenderFunction {

    @Override
    public String doCalculate(String[] fields, RenderDataCompute renderDataCompute) {
        if (fields == null || fields.length == 0) {
            return "";
        }
        String value1 = fields[0];
        String value2 = fields[1];
        Object data1 = renderDataCompute.compute(value1);
        Object data2 = renderDataCompute.compute(value2);
        if (data1 == null) {
            return  Optional.ofNullable(data2).map(Object::toString).orElse("");
        }
        return data1.toString();
    }
}
